package com.base.cn.platform.os.common.feignConfig.hystrix;

import com.netflix.hystrix.Hystrix;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 启用Hystrix后的RequestAttribute属性自动配置类
 * @author s.li
 * @create 2018-10-10-14:36
 */
@Configuration
@ConditionalOnClass({ Hystrix.class })
//获取配置属性
// hystrix.propagate.request-attribute.enabled=true 使用
// hystrix.propagate.request-attribute.enabled=false 不使用
//默认是开启的
@ConditionalOnProperty(value = "hystrix.propagate.request-attribute.enabled", matchIfMissing = true)
//获取hystrix.propagate.request-attribute.enabled配置属性后设置到HystrixRequestAttributeProperties中的属性
@EnableConfigurationProperties(HystrixRequestAttributeProperties.class)
public class HystrixRequestAttributeAutoConfiguration {

    /**
     * 初始化自定义Hystrix并发策略
     * @return RequestAttributeHystrixConcurrencyStrategy
     */
    @Bean
    public RequestAttributeHystrixConcurrencyStrategy hystrixRequestAutoConfiguration() {
        return new RequestAttributeHystrixConcurrencyStrategy();
    }
}
